package byx.container.annotation.extension.impl;

import byx.container.annotation.annotation.Id;
import byx.container.annotation.extension.core.ParameterHandler;
import byx.container.annotation.extension.core.ParameterInfo;
import byx.container.core.Container;
import byx.container.core.ObjectFactory;

import static byx.container.core.ObjectFactories.*;

/**
 * Id注解参数处理器
 */
public class IdParameterHandler implements ParameterHandler {
    @Override
    public boolean support(ParameterInfo param) {
        return param.getAnnotationMetadata().isAnnotationPresent(Id.class);
    }

    @Override
    public ObjectFactory<?> handle(ParameterInfo param, Container container) {
        Id id = param.getAnnotationMetadata().getAnnotation(Id.class);
        return fromContainer(container, id.value());
    }
}
